package controller.devuser;

import mapper.info.InfoMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Devuser;
import pojo.Info;
import pojo.Version;
import service.devuser.DevuserService;
import service.info.InfoService;
import service.version.VersionService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("devuser")
public class DevuserController {
    @Resource
    private DevuserService devuserService;
    @Resource
    private InfoService infoService;
    @Resource
    private VersionService versionService;
    //进入开发者登录页面
    @RequestMapping("/jing")
    public String jing(){
        return "devlogin";
    }
    //开发者登录方法
    @RequestMapping("/getDevuserLogin")
    public String getDevuserLogin(@Param("devCode") String devCode,@Param("devPassword") String devPassword,HttpSession session){
        Devuser devuser=new Devuser();
        try{
            devuser=devuserService.getDevuserLogin(devCode,devPassword);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(devuser!=null){
            session.setAttribute("devuser",devuser);
            return "devindex";
        }else {
            return "devlogin";
        }
    }
    //进入开发者注销
    @RequestMapping("/tozhuxiao")
    public String tozhuxiao(HttpSession session){
        session.setAttribute("devuser",null);
        session.removeAttribute("devuser");
        session.setAttribute("user",null);
        session.removeAttribute("user");
        return "redirect:/index.jsp";
    }


    //跳转到后台查询页面的回显页面
    @RequestMapping("/huiXian")
    public String huiXian(Integer id, Model model){
        Info info=infoService.getHuiXian(id);
        model.addAttribute("app",info);
        List<Version> appVersionList=versionService.getAllAppVersion(id);
        Info in = infoService.getAppInfohuiXian(id);
        model.addAttribute("in",in);
        model.addAttribute("appVersionList",appVersionList);
        return "devlook";
    }

    @RequestMapping("/getuserKaiaudi")
    public String getuserKaiaudi(){
        return "userKaiaudit";
    }


    //403页面跳转到index页面
    @RequestMapping("/jingru")
    public String jingru(){
        return "redirect:/index.jsp";
    }
}
